import configparser
import os
import requests

# 创建配置解析器
config = configparser.ConfigParser()

# 读取配置文件
config.read('config.ini')

# 获取访问令牌
access_token = config.get('artifactory', 'access_token')

# 确保访问令牌已设置
if not access_token:
    raise ValueError("ARTIFACTORY_ACCESS_TOKEN is not set in the config file.")

# JFrog Artifactory的文件URL
file_url = "http://fuckapple2.asuscomm.com:28082/artifactory/daily_storage/Fapiao.zip"

# 指定下载到本地的完整路径
local_path = 'C:\\Users\\awosh\\Desktop\\Jenkins_Download\\Fapiao.zip'

# 设置headers，包括认证信息
headers = {
    'Authorization': f'Bearer {access_token}'
}

# 发送GET请求
response = requests.get(file_url, headers=headers, stream=True)

# 检查响应状态码
if response.status_code == 200:
    # 文件下载成功，写入文件
    with open(local_path, 'wb') as file:
        for chunk in response.iter_content(chunk_size=8192):
            file.write(chunk)
    print(f"文件下载成功，保存在：{local_path}")
else:
    print(f"文件下载失败，状态码：{response.status_code}")